import 'package:flutter/services.dart';
import 'package:flutter_app_demo/base/base_view_model.dart';
import 'package:flutter_app_demo/pigeon/ruixue_plugin.dart';
import 'package:flutter_app_demo/utils/toast.dart';
import 'package:go_router/go_router.dart';

// Created by 王亮 on 2025/2/10.
class TabOnePageViewModel extends BaseViewModel {
  int counter = 0;
  String initRuixueResult = "未初始化瑞雪 SDK";

  @override
  void initState() {
    super.initState();
  }

  void incrementCounter() {
    counter++;
    buildView();
    ToastUtil.showToast(context, "点击了 $counter 次");
  }

  void initRuixueSdk() async {
    final ruixueApi = RuiXueApi();
    try {
      ResponseData response = await ruixueApi.initSdk();
      if (response.code == 0) {
        initRuixueResult = "Ruixue init success";
        buildView();
      } else {
        initRuixueResult = "Ruixue init failed, code: ${response.code} msg: ${response.message ?? "unknown"}";
        buildView();
      }
    } on PlatformException catch (e) {
      initRuixueResult = "Ruixue init failed, code: ${e.code}, ${e.message}";
      buildView();
    }
  }

  void launchOnePage() async {
    final result = await context.push<String>('/one?id=1111&name=leon');
    showToast(result ?? "返回携带参数为空");
  }

  void launchLiveMainPage() => context.push('/live');
}
